<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getHotListApi } from '@/apis/home'
import type { HotType } from '@/apis/components/homeType'
import HomePanel from './HomePanel.vue'

// 人气推荐数据列表
const hotList = ref<[HotType]>()

const getHotList = async () => {
  const res = await getHotListApi()
  hotList.value = res.data.result
}
onMounted(() => getHotList())
</script>

<template>
  <HomePanel title="人气推荐" subTitle="人气爆款 不容错过">
    <template #header></template>

    <ul>
      <li v-for="item in hotList" :key="item.id">
        <RouterLink :to="`/detail/${item.id}`">
          <img v-lazy="item.picture" />
          <div class="p">
            <p class="title">{{ item.title }}</p>
            <p class="alt">{{ item.alt }}</p>
          </div>
        </RouterLink>
      </li>
    </ul>
  </HomePanel>
</template>

<style lang="scss" scoped>
ul {
  display: flex;
  justify-content: space-between;
  li {
    width: 250px;
    height: 400px;
    list-style: none;
    transition: all 0.5s;
    border: 1px solid rgba(0, 0, 0, 0.167);
    .p {
      text-align: center;
      margin-top: 20px;
      font-size: 16px;
      .title {
        font-weight: 400;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .alt {
        padding-top: 10px;
        color: rgba(179, 182, 185, 0.619);
      }
    }
    img {
      width: 100%;
      height: 300px;
    }
    a {
      text-decoration: none;
      color: black;
    }
    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }
  }
}
</style>
